<!doctype html>
<html>
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width,initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;"/>

    <title></title>
<link rel="stylesheet" href="<{$ipath}>wx/style/mobile-vote.css">
<script src="<{$ipath}>wx/js/jquery.min.js"></script>
</head>

<body>
<form action="?index.php&g=c&m=vote&a=submit_vote" method="post">
<div class="container">
    <div class="vote">
      <div class="title">  
        
        <h2><{$vote.name}></h2>
        
        <span class="start-time msg"><{$vote.create_time|date_format:'%Y-%m-%d'}></span><span class="msg">&nbsp;/&nbsp;</span><span class="end-time msg"><{$vote.stop_time|date_format:'%Y-%m-%d'}></span>
      </div>s
      <div class="bg"><img src="<{$ipath}>wx/images/27g58PICcVS_1024.jpg" width="100%"></div>
      <div class="main-vote">
        <p class="tishi">对于您自己的看法，投上你宝贵的一票吧</p>
        

          <{foreach from=$question item=value}>
            <div class="vote_question">
            <input type="hidden" name="question_id" class="question_id" value="<{$value.id}>" />
      
            <{if $value.slec_option eq '0'}>
                <p class="xuan"><span class="blod"><{$value.title}></span>      单选投票<span class="msg msg1">&nbsp;&nbsp;共有<span id="num"><{$value.vote_numbers}></span>人参与投票</span></p>
       
                <ul>
                <{foreach from=$value.options item=value2}>
                    <li class="item">
                    <input type="radio" name="quesion_option" value="<{$value2.option_key}>" class="question_option"> <span><{$value2.option_name}></span>
                    </li>
                <{/foreach}>
                </ul>
                <{else}>

                <p class="xuan"><span class="blod"><{$value.title}></span>      多选投票<span class="msg msg1">&nbsp;&nbsp;共有<span id="num"><{$value.vote_numbers}></span>人参与投票</span></p>

                <ul>
              <{foreach from=$value.options item=value2}>
                  <li class="item">
                     
                     <input type="checkbox"name="quesion_option" value="<{$value2.option_key}>" class="question_option"> <span><{$value2.option_name}></span>
                  </li>
              <{/foreach}>
                </ul>
            <{/if}>       
            </div>
          <{/foreach}>


    <{if !$user_slec}>
        <input class="sure" type="button" value="我要投票"/>
        <{else}>
          
          <p class="already">您已经投过票了</p>
        <div class="resule"><p>您投了，<span class="msg"><{$user_slec}></span></p></div>
      
    <{/if}>
      </div>
    </div>
</div>
        <input type="hidden" name="vote_id" class="vote_id" value="<{$vote.id}>" />
</form>
</body>
</html>
<script>
 
$(".sure").click(function(){

  var vote_id = $(".vote_id").val();
  var vote_dom = $(".vote_question");
  var vote_data = [{}];
  var is_submit=0;

  vote_dom.each(function(){
    var question_id = $(this).find(".question_id").val();
    var question_option = "";
    //选中的checkbox
    var checked = new Array();
    $(this).find(".question_option").each(function(){
        if(this.checked){
          checked.push($(this).val());
        }
    });
    
    if(checked) {
      question_option = checked.join(',');
    } 
    if(checked.length<1){
        is_submit=1;
    }

    var options = {"question_id": question_id, "question_option": question_option};
    vote_data.push(options);
  });
  if(is_submit>0){
    alert("请选择所有投票选项");
  }else{
    $.ajax({
      url: '?index.php&g=c&m=vote&a=submit_vote',
      type: 'POST',
      data: {"data":vote_data, "vote_id": vote_id},
      success: function(){
        location.reload();
      }
  });
    
  }
  
});

</script>